#include "application2d.h"

namespace vortex
{
    Application2d::Application2d(const AppInfo2d& info)
    {
        this->info = info;
    }

    void Application2d::Run()
    {
        while (!Closed())
        {
            BeginFrame();
            Update();
            Render();
            EndFrame();
        }
    }

    bool Application2d::Closed() const
    {
        return window->Closed();
    }

    void Application2d::BeginFrame()
    {
        glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
        // glClearDepth(-1000.0f);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        // support animated texture.
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    }

    void Application2d::EndFrame()
    {
        window->ProcessEvents();
        window->Update();
    }

    void Application2d::InitWindow()
    {
        window = std::make_shared<vortex::Window>(
            info.title, info.window_width, info.window_height
        );
    }
}

